#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=200;

bool next(int o, int b[], int inda[], int to[], int link[], bool book[]) {
  for (int i=inda[o]; i; i=link[i]) {
    if (!b[to[i]]) {
      b[to[i]] = o;
      return true;
    } else if (b[to[i]]!=o && !book[to[i]]) {
      book[to[i]] = true;
      if (next(b[to[i]], b, inda, to, link, book)) {
	b[to[i]] = o;
	return true;
      }
    }
  }
  return false;
}

int match(int n, bool map[][maxn+1]) {
  static int b[maxn+1], inda[maxn+1], to[2*maxn*maxn+1], link[2*maxn*maxn+1];
  int m=0;
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=n; j++) {
      if (map[i][j]) {
	m++;
	to[m] = j;
	link[m] = inda[i];
	inda[i] = m;
      }
    }
  }

  int ans=0;
  static bool book[maxn+1];
  for (int i=1; i<=n; i++) {
    memset(book, 0, sizeof(book))
    ans += next(i, b, inda, to, link, book);
  }
  return ans;
}

int main() {
#ifdef DEBUG
  freopen("3423.in", "r", stdin);
  freopen("3423.out", "w", stdout);
#endif

  static bool map[maxn+1][maxn+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    map[x][y] = true;
  }

  for (int k=1; k<=n; k++) {
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
	map[i][j] = map[i][j] || (map[i][k] && map[k][j]);
      }
    }
  }

  printf("%d", n-match(n, map));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
